package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.map.HashedMap;

import com.google.gson.Gson;

import pojo.BaseDataPojo;
import pojo.College;
import pojo.MessageComment;
import service.BackCollegeService;
import service.BackCommentService;
import service.CollegeService;
import serviceImpl.BackCollegeServiceImpl;
import serviceImpl.BackCommentServiceImpl;
import serviceImpl.CollegeServiceImpl;


@WebServlet("/BackCommentServlet")
public class BackCommentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public BackCommentServlet() {
        super();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String mark = request.getParameter("mark");
		switch(mark) {
		
		case "showMessageComment":   // 获取商城首页轮播图图片
			showMessageComment(request,response);
			break;
		case "delMc":   // 获取商城首页轮播图图片
			delMc(request,response);
			break;
		}
	}

	private void delMc(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int mcid = Integer.parseInt(request.getParameter("mcid"));
		//System.out.println("collegeid:"+collegeid);
		BackCommentService bcs = new BackCommentServiceImpl();
		boolean bo = bcs.delMc(mcid);
		System.out.println(bo);
		
		PrintWriter writer = response.getWriter();
		writer.print(bo);
		
	}


	private void showMessageComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
	
		BackCommentService bcs = new BackCommentServiceImpl();
		ArrayList<MessageComment> mcList = new ArrayList<MessageComment>();
		mcList = bcs.getMc();
		request.setAttribute("messageCommentList", mcList);
		request.getRequestDispatcher("/background/ordUserJs/index/messageComment.jsp").forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
